package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcredit.LindiTradeApplicationCreditQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcredit.LindiTradeApplicationCreditVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;

import java.util.List;
import com.minimalist.lindi.service.LindiTradeApplicationCreditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 林地指标交易平台_交易申请付款凭证控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请付款凭证管理")
@RequestMapping("/lindi/tradeApplicationCredit")
public class LindiTradeApplicationCreditController{

    @Autowired
    private LindiTradeApplicationCreditService service;

    @PostMapping("/addTradeApplicationCredit")
    @Operation(summary = "添加交易申请付款凭证")
    public R<?> addTradeApplicationCredit(
            @RequestBody @Validated(Add.class)
            LindiTradeApplicationCreditVO tradeApplicationCreditVO){
        service.addTradeApplicationCredit(tradeApplicationCreditVO);
        return R.ok();
    }

    @DeleteMapping("/deleteTradeApplicationCreditByTradeApplicationCreditId")
    @Operation(summary = "删除交易申请付款凭证 -> 根据交易申请付款凭证ID删除")
    public R<?> deleteTradeApplicationCreditByTradeApplicationCreditId(
            @RequestParam("tradeApplicationCreditId")
            @NotNull(message = "交易申请付款凭证ID不能为空")
            @Parameter(name = "tradeApplicationCreditId", required = true, description = "交易申请付款凭证ID")
            Long tradeApplicationCreditId){
        service.deleteTradeApplicationCreditByTradeApplicationCreditId(
                tradeApplicationCreditId);
        return R.ok();
    }

    @PutMapping("/updateTradeApplicationCreditByTradeApplicationCreditId")
    @Operation(summary = "修改交易申请付款凭证")
    public R<?> updateTradeApplicationCreditByTradeApplicationCreditId(
            @RequestBody @Validated(Update.class)
            LindiTradeApplicationCreditVO tradeApplicationCreditVO){
        service.updateTradeApplicationCreditByTradeApplicationCreditId(
                tradeApplicationCreditVO);
        return R.ok();
    }

    @GetMapping("/getPageTradeApplicationCreditList")
    @Operation(summary = "查询交易申请付款凭证列表(分页)")
    public R<PageResp<LindiTradeApplicationCreditVO>> getPageTradeApplicationCreditList(
            @RequestBody LindiTradeApplicationCreditQueryVO queryVO){
        return R.ok(service.getPageTradeApplicationCreditList(queryVO));
    }

    @GetMapping("/getTradeApplicationCreditByTradeApplicationCreditId/{tradeApplicationCreditId}")
    @Operation(summary = "根据交易申请付款凭证ID查询交易申请付款凭证")
    public R<LindiTradeApplicationCreditVO> getTradeApplicationCreditByTradeApplicationCreditId(
            @PathVariable(value = "tradeApplicationCreditId")
            @NotNull(message = "交易申请付款凭证ID不能为空")
            @Parameter(name = "tradeApplicationCreditId", description = "交易申请付款凭证ID", required = true)
            Long tradeApplicationCreditId){
        return R.ok(service.getTradeApplicationCreditByTradeApplicationCreditId(
                tradeApplicationCreditId));
    }

    @GetMapping("/getTradeApplicationCreditListByTradeApplicationId/{tradeApplicationId}")
    @Operation(summary = "根据交易申请ID查询交易申请付款凭证列表")
    public R<List<LindiTradeApplicationCreditVO>> getTradeApplicationCreditListByTradeApplicationId(
            @PathVariable(value = "tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", description = "交易申请ID", required = true)
            Long tradeApplicationId){
        return R.ok(service.getTradeApplicationCreditListByTradeApplicationId(
                tradeApplicationId));
    }
}